package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Cart;
import com.fantastic.service.zjs.CartService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/5 19:24
 * @description: 购物车信息请求控制器
 */
@RestController
@RequestMapping("/cart")
public class CartControllerAdmin {

    @Resource
    private CartService cartService;

    /**
     * 查询购物车信息
     *
     * @param cart
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listCart")
    public ResultData listCart(Cart cart, @RequestParam(name="page",
            defaultValue = "1") int pageNum,
                               @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Cart> list = cartService.listCart(cart);
        PageInfo<Cart> PageInfo = new PageInfo<>(list);
        return new ResultData(RespStatusInfo.OK, PageInfo);
    }

    /**
     * 查询单个账号下的单条购物车信息
     *
     * @param cart
     * @return
     */
    @GetMapping("/getCart")
    public ResultData getCart(Cart cart) {
        return new ResultData(RespStatusInfo.OK, cartService.getCart(cart));
    }

    /**
     * 添加购物车信息
     *
     * @param cart
     * @return
     */
    @PostMapping("/insertCart")
    public ResultData insertCart(Cart cart) {
        return new ResultData(RespStatusInfo.OK, cartService.insertCart(cart));
    }

    /**
     * 修改购物车信息
     *
     * @param cart
     * @return
     */
    @PostMapping("/updateCart")
    public ResultData updateCart(Cart cart) {
        return new ResultData(RespStatusInfo.OK, cartService.updateCart(cart));
    }


    /**
     * 删除购物车信息
     *
     * @param cart
     * @return
     */
    @PostMapping("/deleteCart")
    public ResultData deleteCart(Cart cart) {
        return new ResultData(RespStatusInfo.OK, cartService.deleteCart(cart));
    }

}
